package com.WebProject.service.UserDao.impl;

import com.WebProject.mapper.UserMapper;
import com.WebProject.mapper.UserMapperImpl;
import com.WebProject.pojo.t_car;
import com.WebProject.pojo.t_car_zu;
import com.WebProject.pojo.t_user;
import com.WebProject.service.UserDao.UserServiceDao;

import java.util.ArrayList;

/**
 * @PACKAGE_NAME: com.WebProject.service.UserDao.impl
 * @NAME: UserSerbiceDaoImpl
 * @USER: ZhouYongCheng
 * @DATE: 2022/7/29
 * @TIME: 17:31
 * @Description: UserSerbiceDao实现类
 */

public class UserSerbiceDaoImpl implements UserServiceDao {

    private UserMapper mapper = new UserMapperImpl();
    /**
     * 租车
     * @param username 用户名
     * @param car_number 车牌
     * @return true租车成功 反之
     */
    @Override
    public Boolean updateZuCarStatus(String username, String car_number) {
        t_car car = mapper.QueryCarInfoById(car_number);
        if (car.getUseAble() != 1){
            return mapper.updateZuCarStatus(username,car_number);
        }
        return false;
    }

    /**
     * 还车
     * @param car_number 车牌
     * @return true 还车成功 反之
     */
    @Override
    public Boolean updateHuanCarStatus(String car_number) {
        return mapper.updateHuanCarStatus(car_number);
    }

    /**
     * 注册
     * @param user userBean
     * @return true注册成功 反之
     */
    @Override
    public Boolean registerUser(t_user user) {
        String username = user.getUsername();
        ArrayList<t_user> t_users = mapper.QueryAllUserInfo();
        for (t_user t_user : t_users) {
            if (username.equals(t_user.getUsername())){
                return false;
            }
        }
        mapper.registerUser(user);
        return true;
    }

    /**
     * 查询所有车辆信息
     * @return 车辆集合
     */
    @Override
    public ArrayList<t_car> QueryAllCarInfo() {
        ArrayList<t_car> cars = mapper.QueryAllCarInfo();
        if (cars != null){
            return cars;
        }
        return null;
    }

    @Override
    public ArrayList<t_user> QueryAllUserInfo() {
        ArrayList<t_user> t_users = mapper.QueryAllUserInfo();
        if (t_users !=null){
            return t_users;
        }
        return null;
    }

    /**
     * 查询该类型的所有车辆
     * @param Type 车辆类型
     * @return 车辆类型集合
     */
    @Override
    public ArrayList<t_car> QueryAllTypeCar(String Type) {
        ArrayList<t_car> cars = mapper.QueryAllTypeCar(Type);
        if (cars != null){
            return cars;
        }
        return null;
    }

    /**
     * 查询该品牌的所有车辆
     * @param Brand 品牌
     * @return 品牌车辆集合
     */
    @Override
    public ArrayList<t_car> QueryAllBrandCar(String Brand) {
        ArrayList<t_car> cars = mapper.QueryAllBrandCar(Brand);
        if (cars != null){
            return cars;
        }
        return null;
    }

    /**
     * 查询该用户所有的租借信息
     * @param username
     * @return
     */
    @Override
    public ArrayList<t_car_zu> QuerUserZuInfo(String username) {
        ArrayList<t_car_zu> t_car_zus = mapper.QuerUserZuInfo(username);
        if (t_car_zus != null){
            return t_car_zus;
        }
        return null;
    }

    @Override
    public t_car QueryCarInfoById(String car_number) {
        t_car car = mapper.QueryCarInfoById(car_number);
        if (car != null){
            return car;
        }
        return null;
    }

    @Override
    public ArrayList<t_car_zu> QueryCarOrder(String username) {
        return mapper.QueryCarOrder(username);
    }

    @Override
    public Boolean deleteUser(String username) {
        return mapper.deleteUser(username);
    }

    @Override
    public t_user QueryUserInfo(String username) {
        return mapper.QueryUserInfo(username);
    }

    @Override
    public Boolean changePassword(String username, String password) {
        return mapper.changePassword(username,password);
    }

    @Override
    public ArrayList<t_car> QueryCar(String order) {
        ArrayList<t_car> cars = mapper.QueryCar(order);
        if (cars != null){
            return cars;
        }
        return null;
    }

    @Override
    public ArrayList<t_car> QueryAllBrandAndCategory(String brand, String category) {
        return mapper.QueryAllBrandAndCategory(brand,category);
    }
}
